package co.edu.eam.laapuesta.persistencia.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import co.edu.eam.laapuesta.persistencia.entidades.Giro;
import co.edu.eam.laapuesta.persistencia.entidades.Reclamo_Giro;
import co.edu.eam.laapuesta.persistencia.entidades.Sucursal;
import co.edu.eam.laapuesta.persistencia.idao.GiroIDAO;

public class GiroDAO implements GiroIDAO {

	private EntityManager em;

	public GiroDAO(EntityManager em) {
		this.em = em;
	}

	@Override
	public void crearGiro(Giro giro) {
		// TODO Auto-generated method stub
		em.persist(giro);
	}

	@Override
	public Giro buscarGiro(long id) {
		// TODO Auto-generated method stub
		return em.find(Giro.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Giro> listarGiros() {
		// TODO Auto-generated method stub
		Query q = em.createNamedQuery(Giro.FIND_ALL);
		return q.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Giro> listarGiroXSucursal(Sucursal sucursal) {
		// TODO Auto-generated method stub
		String q = "select g from Giro g join sucursal s on g.sucursal = s.id where s.id = "
				+ sucursal.getId() + "";
		Query qu = em.createNamedQuery(q);
		return qu.getResultList();
	}

	@Override
	public void crearReclamosGiro(Reclamo_Giro reclamo_giro) {
		// TODO Auto-generated method stub
		em.persist(reclamo_giro);
	}

	@Override
	public Reclamo_Giro buscarReclamoGiro(long id) {
		// TODO Auto-generated method stub
		return em.find(Reclamo_Giro.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Reclamo_Giro> listarReclamosGiros() {
		// TODO Auto-generated method stub
		Query q = em.createNamedQuery(Reclamo_Giro.FIND_ALL);
		return q.getResultList();
	}

}
